package graphicView;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.*;

import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;



public  class GUI2 extends JPanel
implements MouseListener, ActionListener {

private static final long serialVersionUID = 1L;

private JFrame frame;
private GraphicController controller;
private JTextField inputField;
private JTextArea theOutputMessage;
private JScrollPane JSP;
private Container Panel;
private LayoutManager Layout;

private static final String saveMenuText = "Save UML";
private static final String openMenuText = "Open UML";
private static final String insertText = "Insert";
private static final String relationshipText = "Relationship";
private static final String classText = "Class";
private static final String packageText = "Package";
private static final String findButtonText = "Find Word";



public GUI2(GraphicController aController, JFrame aFrame) {
	frame = aFrame;
	controller = aController;
   	JPanel widgetPanel = setupLayout();
   	frame.getContentPane().add(widgetPanel, BorderLayout.CENTER);
	createMenu(frame);
	//createTextItems(widgetPanel);
	//createButton(widgetPanel);
	//setSizes();
	addMouseListener(this);
}




private void setSizes() {
	/*		Puzzle thePuzzle = puzzle();
	Dimension puzzleDrawingSize = new Dimension (thePuzzle.numberOfColumns()*LetterSize + borderSize*2,
			 thePuzzle.numberOfRows()*LetterSize + borderSize*2);
setMinimumSize(puzzleDrawingSize);
setPreferredSize(puzzleDrawingSize);
setMaximumSize(puzzleDrawingSize);
revalidate();*/
	
}




private void createTextItems(JPanel widgetPanel) {
	// TODO Auto-generated method stub
	
}




private void createButton(JPanel widgetPanel) {
	// TODO Auto-generated method stub
	
}




private void createMenu(JFrame frame2) {
	
	//The Black State
	JMenuItem subMenuItem;
	JMenu	Insert;
	
	// create a menu bar
	JMenuBar menuBar = new JMenuBar();
	frame.setJMenuBar(menuBar);
			
	// create the File Item on the menu bar
	JMenu fileMenu = new JMenu("File"); 
	menuBar.add(fileMenu);

	
	// create the openPuzzle submenu item and listen for it
	JMenuItem openPuzzle = new JMenuItem(openMenuText); 
	openPuzzle.addActionListener(this);
	fileMenu.add(openPuzzle);
	
	// create the savePuzzle submenu item and listen for it
	JMenuItem savePuzzle = new JMenuItem(saveMenuText); 
	savePuzzle.addActionListener(this);
	fileMenu.add(savePuzzle);
	
	// create the Edit Item on the menu bar
	JMenu editMenu = new JMenu("Edit"); 
	menuBar.add(editMenu);
	
/*		JMenuItem Insert = new JMenuItem(insertText); 
	Insert.addActionListener(this);
	editMenu.add(Insert);*/
	
	
	JMenuItem Package = new JMenuItem(packageText); 
	Package.addActionListener(this);
	
	JMenuItem Class = new JMenuItem(classText);
	Class.addActionListener(this);
	
	JMenuItem Relationship = new JMenuItem(relationshipText);
	Relationship.addActionListener(this);
	
		
	Insert = new JMenu("Insert");
	Insert.setMnemonic(KeyEvent.VK_S);
	subMenuItem = new JMenuItem("Package");
	/*subMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
			ActionEvent.CTRL_MASK));*/
	subMenuItem.addActionListener(this);
	Insert.add(subMenuItem);
	subMenuItem = new JMenuItem("Class");
	Insert.add(subMenuItem);
	subMenuItem.addActionListener(this);
	subMenuItem = new JMenuItem("Relationship");
	Insert.add(subMenuItem);
	subMenuItem.addActionListener(this);
	
	editMenu.add(Insert);
	
}




private JPanel setupLayout() {
	
/*    setSize(300, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);

    JPanel p = new JPanel();
    p.setSize(600, 400);
    p.setLayout(new BorderLayout());
	
    JSP = new JScrollPane(p);
    getContentPane().add(JSP, BorderLayout.CENTER);*/
    
   AdjustmentListener adjustmentListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
          System.out.println("Adjusted: " + adjustmentEvent.getValue());
        }
      };		
	
     JLabel label  = new JLabel(); 
      
     
    Layout = new BorderLayout();
    setLayout(new BorderLayout());
	JPanel widgetPanel = new JPanel();
	
	JScrollPane JSP = new JScrollPane(widgetPanel);
	
	
//	Panel = getContentPane();
	
/*	JFrame JFK = new JFrame();
	JFK.setContentPane(new JScrollPane());
	JFK.getContentPane().add(widgetPanel);
	//JFK.getContentPane().add(JSP, BorderLayout.CENTER);
    JFK.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JFK.setSize(400,400);
    JFK.setVisible(true);     
    
   
    
	JScrollBar JSBH = new JScrollBar(JScrollBar.HORIZONTAL, 10, 10, 0, 500);
	//JSBH.setMaximum(500);
	JSBH.addAdjustmentListener(adjustmentListener);
	
	  JSBH.setUnitIncrement(2);
      JSBH.setBlockIncrement(1);
	
	
	JScrollBar JSBV = new JScrollBar(JScrollBar.VERTICAL, 10, 10, 0, 500);
	//JSBV.setMaximum(400);
	JSBV.addAdjustmentListener(adjustmentListener);
	
	JSBH.setOrientation(JScrollBar.HORIZONTAL);*/
	
	widgetPanel.setPreferredSize(new Dimension(400, 400));
	widgetPanel.setBorder(BorderFactory.createLineBorder(Color.blue,  2));
	
	//widgetPanel.add(JSBH, "North");
	
	//JFK.add(JSP);
    
    
    
    
	return widgetPanel;
}




@Override
public void actionPerformed(ActionEvent arg0) {
	// TODO Auto-generated method stub
	
}
@Override
public void mouseClicked(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}
@Override
public void mouseEntered(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}
@Override
public void mouseExited(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}
@Override
public void mousePressed(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}
@Override
public void mouseReleased(MouseEvent arg0) {
	// TODO Auto-generated method stub
	
}

public void printMessage(String theMessage) {
	theOutputMessage.setText(theMessage);
}

public String obtainFileName(String message) {
	String theFileName = null;
	final JFileChooser fc = new JFileChooser();
	int returnVal = fc.showOpenDialog(this);
	if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = fc.getSelectedFile();
           try {
        	   theFileName = file.getCanonicalPath();
           } catch (Exception e) {
        	   printMessage("Unable to determine file path.");
        	   theFileName = null;
           }
	}
		return (theFileName);
}

}